import {reqGoodsDetailInfoData} from '@/api/index'

const state={
    goodsDetailInfo:{}
}

const actions={
    async getGoodsDetailInfoData(context,id){
        const res = await reqGoodsDetailInfoData(id)
        if(res.code === 200){
            context.commit('SAVE_GOODS_DETAIL_INFO_DATA',res.data)
        }else{
            console.log(res.message);
        }
    }
}

const mutations={
    // 1. 存储商品详情数据
    SAVE_GOODS_DETAIL_INFO_DATA(state,value){
        state.goodsDetailInfo = value
    },

    // 2.更改skuInfo中的放大镜图片地址
    UPDATE_SKUINFO_IMGURL(state,imgUrl){
        state.goodsDetailInfo.skuInfo.skuDefaultImg = imgUrl
    }
}

const getters={
    categoryView(state){
        return state.goodsDetailInfo.categoryView || {}
    },
    skuInfo(state){
        return state.goodsDetailInfo.skuInfo || {}
    },
    spuSaleAttrList(state){
        return state.goodsDetailInfo.spuSaleAttrList || {}
    }
}

export default {
    namespaced:true,
    state,
    actions,
    mutations,
    getters
}